package test;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.*;
import org.jeecgframework.codegenerate.window.CodeWindow;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;


/**
 * 【单表模型】代码生成器入口
 * @author 张代浩
 * @site www.jeecg.org
 *
 */
public class JeecgOneGUI {

	public static void main(String[] args) {
		long s = System.currentTimeMillis();
//		testXSSWork();
		testSXSSWork();
		long e = System.currentTimeMillis();
		System.out.println(e - s);
	}


	public static void testXSSWork() {
		OutputStream out = null;
		try {
			String str = "d:/test1.xls";
			File file = new File(str);
			if(!file.exists()) file.createNewFile();
			out = new FileOutputStream(file);
			XSSFWorkbook workbook = new XSSFWorkbook();
			XSSFSheet sheet =  workbook.createSheet("sheet0");
			for(int i=0; i<65500; i++) {
				XSSFRow row = sheet.createRow(i);
				for(int j=0; j<10; j++) {
					XSSFCell cell = row.createCell(j);
					XSSFRichTextString text = new XSSFRichTextString(j + "");
					cell.setCellValue(text);
				}
			}
			workbook.write(out);
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			if(out != null) {
				try {
					out.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

	public static void testSXSSWork() {
		OutputStream out = null;
		try {
			String str = "d:/test2.xlsx";
			File file = new File(str);
			if(!file.exists()) file.createNewFile();
			out = new FileOutputStream(file);
			SXSSFWorkbook workbook = new SXSSFWorkbook(1000);
			Sheet sheet = workbook.createSheet("sheet0");
			for(int i=0; i<65500; i++) {
				Row row = sheet.createRow(i);
				for(int j=0; j<10; j++) {
					Cell cell = row.createCell(j);
					cell.setCellType(XSSFCell.CELL_TYPE_STRING);//文本格式
					cell.setCellValue(j + "");
				}
			}
			workbook.write(out);
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			if(out != null) {
				try {
					out.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
